package com.mf.controller;

import javax.servlet.http.HttpServletRequest;

import com.mf.entity.Msg;
import com.mf.entity.Picture;
import com.mf.service.PictureService;
import com.mf.util.DeleteFileUtil;


public class PictureController {
	PictureService pictureService=  new PictureService();
	

	
	public Msg list(HttpServletRequest request){
		
		
		
		Msg msg=Msg.success().add("pictureList", pictureService.AllPicture());
		
		//request.setAttribute("pictureList",msg );
		return msg;
	}
	
	public Msg deletePicture(String id,String realname){
		Picture picture=new Picture();
		int intId=Integer.parseInt(id);
		picture.setId(intId);
		pictureService.delete(picture);
		DeleteFileUtil.deleteFile("/home/upload/imgs/"+realname);
		return Msg.success();
	}
	
	public Msg getPictureById(String id){
		
		Picture picture=new Picture();
		int intId=Integer.parseInt(id);
		picture.setId(intId);
		picture=pictureService.select(picture);
		return Msg.success().add("picture", picture);
	}
	
	public Msg pictureUpadte(Picture picture){
		pictureService.update(picture);
		return Msg.success();
	}
}
